package com.info33.platform.system.controller;

import java.util.List;

import javax.validation.Valid;

import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.info33.platform.system.dto.SysAnnouncementAuthDTO;
import com.info33.platform.system.entity.SysAnnouncementAuth;
import com.info33.platform.system.service.SysAnnouncementAuthService;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/SysAnnouncementAuth")
@Api(tags = "系统 - 公告权限表")
public class SysAnnouncementAuthController extends BaseController<SysAnnouncementAuthService,SysAnnouncementAuth> {

	private final SysAnnouncementAuthService sysAnnouncementAuthService;
	
	public SysAnnouncementAuthController(SysAnnouncementAuthService baseService) {
		super(baseService);
		this.sysAnnouncementAuthService = baseService;
	}

	/********************************************************************************
	 * @Title: get
	 * @Description: 通过id获取公告权限表详情
	 ********************************************************************************/
	@GetMapping(value = "/{id}")
	@ApiOperation(value = "获取公告权限表详情", notes = "通过ID获取公告权限表详情")
	public Result<SysAnnouncementAuth> get(@PathVariable(value = "id") Long id) throws Exception {
		return Result.ok(sysAnnouncementAuthService.getById(id));
	}


	/********************************************************************************
	 * @Title: getlist
	 * @Description: 通过条件获取公告权限表全部列表
	 ********************************************************************************/
	@PostMapping(value = "/list")
	@ApiOperation(value = "获取公告权限表详情", notes = "通过条件获取公告权限表详情 pageNum 和 pageSize 都为 0 的时候就是查询全部数据")
	public Result<List<SysAnnouncementAuth>> getlist(@RequestBody SysAnnouncementAuth sysAnnouncementAuth) throws Exception {
		return Result.ok(sysAnnouncementAuthService.list(new QueryWrapper<SysAnnouncementAuth>(sysAnnouncementAuth)));
	}
	
	/********************************************************************************
	 * @Title: getlist
	 * @Description: 通过条件获取公告权限表分页列表
	 ********************************************************************************/
	@PostMapping(value = "/list/page/{pageNum}/{pageSize}")
	@ApiOperation(value = "获取公告权限表详情", notes = "通过条件获取公告权限表详情")
	public Result<IPage<SysAnnouncementAuth>> getlist(@RequestBody SysAnnouncementAuth sysAnnouncementAuth, @PathVariable int pageNum, @PathVariable int pageSize) throws Exception {
		IPage<SysAnnouncementAuth> page = new Page<SysAnnouncementAuth>(pageNum, pageSize);
		return Result.ok(sysAnnouncementAuthService.page(page, new QueryWrapper<SysAnnouncementAuth>(sysAnnouncementAuth)));
	}
	

	/********************************************************************************
	 * @Title: add
	 * @Description: 新增单个公告权限表详情
	 ********************************************************************************/
	@PostMapping("/add")
	@ApiOperation(value = "新增单个公告权限表详情", notes = "新增单个公告权限表详情")
	public Result<SysAnnouncementAuth> add( @RequestBody SysAnnouncementAuthDTO sysAnnouncementAuthDTO)  throws Exception {
		SysAnnouncementAuth sysAnnouncementAuth = new SysAnnouncementAuth();
		BeanUtils.copyProperties(sysAnnouncementAuthDTO, sysAnnouncementAuth);
		return sysAnnouncementAuthService.save(sysAnnouncementAuth)?Result.ok(sysAnnouncementAuthService.getById(sysAnnouncementAuth.getId())):Result.error();
	}

	/********************************************************************************
	 * @Title: addBatch
	 * @Description: 新增多个公告权限表详情
	 ********************************************************************************/
	@PostMapping("/addBatch")
	@ApiOperation(value = "新增多个公告权限表详情", notes = "新增多个公告权限表详情")
	public Result<List<SysAnnouncementAuth>> addBatch(@RequestBody List<SysAnnouncementAuth> sysAnnouncementAuthList)  throws Exception {
		//批量的校验无效，需要自己写校验
		return sysAnnouncementAuthService.saveBatch(sysAnnouncementAuthList)?Result.ok(sysAnnouncementAuthList):Result.error();
	}

	/********************************************************************************
	 * @Title: update
	 * @Description: 更新单个公告权限表详情
	 ********************************************************************************/
	@PostMapping("/edit")
	@ApiOperation(value = "更新单个公告权限表详情", notes = "更新单个公告权限表详情")
	public Result<SysAnnouncementAuth> edit(@Valid @RequestBody SysAnnouncementAuth sysAnnouncementAuth, BindingResult bindingResult)  throws Exception {
		return sysAnnouncementAuthService.updateById(sysAnnouncementAuth)?Result.ok(sysAnnouncementAuthService.getById(sysAnnouncementAuth.getId())):Result.error();
	}

	/********************************************************************************
	 * @Title: editBatch
	 * @Description: 更新多个公告权限表详情
	 ********************************************************************************/
	@PostMapping("/editBatch")
	@ApiOperation(value = "更新多个公告权限表详情", notes = "更新多个公告权限表详情")
	public Result<List<SysAnnouncementAuth>> editBatch(@RequestBody List<SysAnnouncementAuth> sysAnnouncementAuthList)  throws Exception {
		//批量的校验无效，需要自己写校验
		return sysAnnouncementAuthService.updateBatchById(sysAnnouncementAuthList)?Result.ok(sysAnnouncementAuthList):Result.error();
	}

	/********************************************************************************
	 * @Title: remove
	 * @Description: 删除单个公告权限表详情
	 ********************************************************************************/
	@PostMapping("/remove/{id}")
	@ApiOperation(value = "删除单个公告权限表详情", notes = "删除单个公告权限表详情")
	public Result<?> remove(@PathVariable(value = "id") Long id)  throws Exception {
		return sysAnnouncementAuthService.removeById(id)?Result.ok():Result.error();
	}

}
